#include "pushbox.h"
#include "ui_pushbox.h"
#include"tip.h"
#include<QMessageBox>
#include<QProcess>
#include<qdir.h>
pushbox::pushbox(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::pushbox)
{
    ui->setupUi(this);
    setFixedSize(8*64,8*64);
    setWindowTitle("杰哥地牢----by姚翙载");
    pbox=new game;
    pmap=new QPainter(this);
}

pushbox::~pushbox()
{
    delete ui;
}

void pushbox::keyPressEvent(QKeyEvent *event)
{
    pbox->Key(event);
    if(pbox->gameover()){
        QMessageBox msgbox;
        msgbox.setWindowTitle("恭喜通关");
        msgbox.setText("            杰哥ㄜˋ不要啦~            ");
        msgbox.exec();
        this->close();
    }
}

void pushbox::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    pmap->begin(this);
    pbox->drawmap(pmap);
    pmap->end();
    update();
}

void pushbox::on_actionremake_triggered()//QProcess重启槽函数
{
    QString program = QApplication::applicationFilePath();
        QStringList arguments = QApplication::arguments();
        QString workingDirectory = QDir::currentPath();
        QProcess::startDetached(program, arguments, workingDirectory);
        QApplication::exit();
}
